﻿@model TouristGuide.Models.Country

@{
    ViewBag.Title = Model.Name;
}

<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"></script>
<script type="text/javascript">
    $(document).ready(function () {
        GetMap();
        //call the action created to retrieve the data
        $.post("/Country/AttractionsForCountry?country=@Model.Name", null, function (data) {
            //iterate through the 'data' retireved
            $.each(data, function (item, location) {
                AddLocationPin(location.Latitude, location.Longitude, location.Title, location.Description);
            });
        });
    });
    var map = null;
    function GetMap() {
        map = new VEMap('myMap');
        map.LoadMap(new VELatLong(@Model.Coordinates.Latitude, @Model.Coordinates.Longitude), 5, 'Road', false);
    }
    function AddLocationPin(latitude, longitude, title, description) {      
        //create new pushpin shape      
        shape = new VEShape(VEShapeType.Pushpin, new VELatLong(latitude, longitude));      
        //set title for info box      
        shape.SetTitle(title);      
        //set html for info box      
        shape.SetDescription(description);      
        //add pin      
        map.AddShape(shape);  
    }

</script>

@if (Request.IsAuthenticated && HttpContext.Current.User.IsInRole("admin"))
{
    <p>
        @Html.ActionLink("Edit", "Edit", new { id = Model.ID }) |
        @Html.ActionLink("Delete", "Delete", new { id = Model.ID }) |
        @Html.ActionLink("Back to List", "Index")
    </p>
}

<div class="center">
    @Html.ActionLink("Cities/Regions","Index","Place", new {country = Model.Name},null) | 
    @Html.ActionLink("Attractions", "Index", "Attraction", new { country = Model.Name },null)
</div>
<br />
<div id='myMap' style="position: relative; width: 600px; height: 400px">
</div>
<p>@Html.Raw(Model.Description)</p>

